home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
tcoop10a.zip
/
DEMO.ZIP
/
TESTWIND.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-20
|
4KB
|
157 lines
//
// WINDOWS.CPP
// version 1.00 11/15/91
// window demo uses Window, Menu and Control Classes
// copyright (c) 1991 by James S. Clark
// all rights reserved
//
#include <stdlib.h>
#include <dos.h> // pokeb()
#include <conio.h> // colors
#include "window.hpp"
#include "menu.hpp"
#include "control.hpp"
// EXTERNALS
extern unsigned VideoBaseAddr;
colors MICROCOLORS = { 0x3E, 0x3B, 0x30, 0x7E, 0x3F, 0x3E, 0x3F, 0x7F };
colors TURBOCOLORS = { 0x1E, 0x17, 0x1E, 0x5E, 0x1F, 0x1F, 0x1B, 0x5B };
// TEST MENU CONSTANTS
char *MAINMENU = "> \xF0 > File > Edit > Setup > Options > Window > Help ";
char *FILEMENU = ">Open... Alt-A>New>Save>Save as...>->Directory>Quit\0";
char *COMMANDMENU[] = {
"> \xF0 > File > Edit > Options > Window > Help ",
">Copyright...>About...\0",
">Open... Alt-A>New>Save>Save as...>->Directory>Quit\0",
">Cut>Move>Paste>Delete>Write block>Read block\0",
">Memory>Display>Printer>Disk\0",
">Close>Move>Resize>Zoom\0",
">Dictionary>General>On Help\0"
};
// ATTR - returns text attribute of fore/back colors
int attr(int forecolor, int backcolor)
{
return(backcolor << 4 | forecolor);
}
// CLEARDESK - clears the desk top
void cleardesk()
{
register int i;
char ccolor = attr(LIGHTGRAY, BLACK);
for (i=0; i<4000; i+=2)
pokeb(VideoBaseAddr, i, 0xB0);
pokeb(VideoBaseAddr, i+1, ccolor);
}
int mastermenu(MenuBar *menubar, Menu *menu, char *menus[], colors *clr)
{
int x, y;
int sel = 0, sel1 = 0, sel2 = 0;
menubar = new MenuBar(NULL, 1, 1, NULL, menus[0], clr);
while (sel == 0) {
sel1 = menubar->select() + 1;
if (sel1 > 0) {
x = wherex() - 1;
y = wherey() + 1;
menu = new Menu(NULL, x, y, W_FRAME|W_EMBOSS|W_SHADOW, menus[sel1], clr);
sel2 = menu->select();
if (sel2 > 0) sel = sel1 * 100 + sel2;
if (sel2 == -2) {
sel1--;
// if (sel1 < 0) sel1 = menubar->maxitems;
}
if (sel2 == -3) {
sel1++;
// if (sel1 > menubar->maxitems) sel1 = 0;
}
}
}
return(sel);
}
main()
{
Window *theWindow[10];
MenuBar *theMenuBar;
Menu *theMenu;
Control *theCtrl[10];
int windnum = 9;
int x, y;
int i;
randomize();
theWindow[0]->startup();
cleardesk();
for (i=0; i<windnum; i++) {
x = 1 + random(53);
y = 1 + random(17);
theWindow[i] = new Window("MR. WINDOW", x, y, x+25, y+7, W_FRAME|W_TITLE|W_SHADOW, NULL);
theWindow[i]->textbox(1, 1, 24, 6, random(3)+1,
"This is a text box from hell!!!! Hope you like it Dude!");
delay(250);
getch();
}
for (i=windnum-1; i>=0; i--) {
theWindow[i]->close();
delete theWindow[i];
delay(250);
}
/* open a couple of test menus */
// mastermenu(theMenuBar, theMenu, COMMANDMENU, &TURBOCOLORS);
theMenuBar = new MenuBar(NULL, 1, 1, NULL, MAINMENU, &TURBOCOLORS);
theMenuBar->select();
theMenu = new Menu("File", 10, 10, W_FRAME|W_TITLE|W_EMBOSS|W_SHADOW, FILEMENU, &TURBOCOLORS);
theMenu->select();
delay(500);
theMenu->close();
delay(500);
theMenuBar->close();
/* open a test window with controls */
theWindow[1] = new Window("CONTROL WINDOW", 5, 4, 75, 20, W_FRAME|W_TITLE|W_SHADOW, NULL);
theCtrl[1] = new Control(theWindow[1], C_CHECK, "Completed", 10, 8, W_EMBOSS, 1, NULL); theCtrl[2] = new Control(theWindow[1], C_BUTTON, " Load ", 10, 10, W_EMBOSS, 0, NULL);
theCtrl[3] = new Control(theWindow[1], C_FIELD, "Echo only", 10, 12, W_EMBOSS, 20, NULL);
theCtrl[4] = NULL;
theCtrl[3]->setstr("Test Text ");
theCtrl[3]->draw(0);
ControlSelect(&theCtrl[1]);
for (i=1; i<4; i++) delete theCtrl[i];
delay(500);
theWindow[1]->close();
delay(500);
return(0);
}